package com.shen;

import java.io.*;
import java.util.Scanner;

/**
 * Author:shen
 * CreateDate:2020/6/3.
 * Function:
 */
public class demo08 {
    static Scanner scanner=new Scanner(System.in);
    public static void main(String[] args) {

        System.out.println("请输入一个文件名：");
        String fileName=scanner.nextLine();
        File file=new File(fileName);
        if(file.exists()&&file.isFile()){
            putFileLine(file);
        }else{
            System.out.println("请输入一个正确的文件名");
        }

    }
    public static void putFileLine(File file){
        FileReader fileReader=null;
        BufferedReader bufferedReader=null;
        try {
            fileReader=new FileReader(file);
            bufferedReader=new BufferedReader(fileReader);
            int count=0;
            while (bufferedReader.readLine()!=null){
                count++;
            }
            System.out.println(count);
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            try {
                if(fileReader!=null){
                    fileReader.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

    }

}
